package com.ruoyi.web.controller.exam;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.exam.domain.vo.ExamPaperVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.TExamPaper;
import com.ruoyi.exam.service.ITExamPaperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测评试卷Controller
 *
 * @author Bandit
 * @date 2022-11-01
 */
@RestController
@RequestMapping("/exam/paper")
public class TExamPaperController extends BaseController
{
    @Autowired
    private ITExamPaperService tExamPaperService;

    /**
     * 查询测评试卷列表
     */
    @PreAuthorize("@ss.hasPermi('exam:paper:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamPaperVo examPaperVo)
    {
        startPage();
        List<ExamPaperVo> list = tExamPaperService.selectExamPaperVoList(examPaperVo);
        return getDataTable(list);
    }

    /**
     * 导出测评试卷列表
     */
    @PreAuthorize("@ss.hasPermi('exam:paper:export')")
    @Log(title = "测评试卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TExamPaper tExamPaper)
    {
        List<TExamPaper> list = tExamPaperService.selectTExamPaperList(tExamPaper);
        ExcelUtil<TExamPaper> util = new ExcelUtil<TExamPaper>(TExamPaper.class);
        util.exportExcel(response, list, "测评试卷数据");
    }

    /**
     * 获取测评试卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:paper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tExamPaperService.selectExamPaperVoById(id));
    }

    /**
     * 新增测评试卷
     */
    @PreAuthorize("@ss.hasPermi('exam:paper:add')")
    @Log(title = "测评试卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamPaperVo examPaperVo)
    {
        return toAjax(tExamPaperService.insertExamPaperVo(examPaperVo));
    }

    /**
     * 修改测评试卷
     */
    @PreAuthorize("@ss.hasPermi('exam:paper:edit')")
    @Log(title = "测评试卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamPaperVo examPaperVo)
    {
        return toAjax(tExamPaperService.updateExamPaperVo(examPaperVo));
    }

    /**
     * 删除测评试卷
     */
    @PreAuthorize("@ss.hasPermi('exam:paper:remove')")
    @Log(title = "测评试卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tExamPaperService.deleteTExamPaperByIds(ids));
    }
}
